package org.emavaj.sanguosha.model.vo;

import java.io.Serializable;

import org.emavaj.common.ReflectUtil;
import org.emavaj.sanguosha.model.card.AbstractCard;
import org.emavaj.sanguosha.model.exception.SGSException;

/**
 * User: dizem Time: 11-4-26 上午8:08
 * 
 * eMavaj updated 20120918
 */
public class CardVO implements Serializable {

	private static final long serialVersionUID = 8425399522550889988L;
	
	protected byte suit;
	protected byte color;
	protected String rank;
	protected String name;
	// protected String description;
	// protected String filename;

	private byte weaponRange;
	private byte attRange;
	private byte defRange;
	private boolean selectable;

	private String className;

	public CardVO() {
	}

	// public CardVO(AbstractCard card) {
	// this.suit = card.getSuit();
	// this.color = card.getColor();
	// this.rank = card.getRank();
	// this.name = card.getName();
	// this.description = card.getDescription();
	// this.filename = card.getFilename();
	// this.cardType = -1;
	//
	// if (card instanceof AbstractEquipmentCard) {
	// // this.range = ((AbstractEquipmentCard) card).getRange();
	// this.cardType = ((AbstractEquipmentCard) card).getEquipmentType();
	// }
	// // this.cardType = card.getCategory();
	//
	//
	// }

	public AbstractCard toCard() {
		if (this.className == null || "".equals(this.className)) {
			throw new SGSException("vo's classname is null or empty");
		}
		AbstractCard card = null;
		try {
			card = (AbstractCard) ReflectUtil
					.getClassInstance(this.className);
			card.fromCardVO(this);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return card;
	}

	public int getSuit() {
		return suit;
	}

	public void setSuit(int suit) {
		this.suit = (byte) suit;
	}

	public int getColor() {
		return color;
	}

	public void setColor(int color) {
		this.color = (byte) color;
	}

	public String getRank() {
		return rank;
	}

	public void setRank(String rank) {
		this.rank = rank;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	// public String getDescription() {
	// return description;
	// }

	// public void setDescription(String description) {
	// this.description = description;
	// }

	// public String getFilename() {
	// return filename;
	// }
	//
	// public void setFilename(String filename) {
	// this.filename = filename;
	// }

	// public int getCardType() {
	// //return cardType;
	// return 0;
	// }
	//
	// public void setCardClassname(String className) {
	// //this.cardType = cardType;
	// }

	public int getAttRange() {
		return attRange;
	}

	public void setAttRange(int range) {
		this.attRange = (byte) range;
	}
	
	public int getWeaponRange() {
		return weaponRange;
	}

	public void setWeaponRange(int weaponRange) {
		this.weaponRange = (byte) weaponRange;
	}

	public int getDefRange() {
		return defRange;
	}

	public void setDefRange(int defRange) {
		this.defRange = (byte) defRange;
	}

	public boolean isSelectable() {
		return selectable;
	}

	public void setSelectable(boolean selectable) {
		this.selectable = selectable;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	// public static void main(String[] args) {
	// CardVO vo = new CardVO(Deck.getInstance().popCard());
	// System.out.println(JSONUtil.convertToString(vo));
	// }
}
